//
//  SettingViewController.m
//  QuickCure37
//
//  Created by 马文星 on 16/6/18.
//  Copyright © 2016年 Demos. All rights reserved.
//

#import "SettingViewController.h"
#import "SettingTableViewCell.h"
#import "LeftViewController.h"

@interface SettingViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) NSArray *cellArr;

@end

//cellID
static NSString *cellID = @"tabCell";

@implementation SettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    [self getData];
    
    [self setupUI];
}

#pragma mark
#pragma mark - 获取数据
-(void)getData{
    
    //数组
    self.cellArr = @[@"意见反馈",@"加号符号说明",@"修改密码",@"注销用户"];
}


#pragma mark
#pragma mark - 搭载界面
-(void)setupUI{
    
    //创建tableView
    UITableView *tabV = [[UITableView alloc] init];
    
    //添加tabView
    [self.view addSubview:tabV];
    
    //设置代理和数据源方法
    tabV.dataSource = self;
    tabV.delegate = self;
    
    //注册cell
    [tabV registerClass:[SettingTableViewCell class] forCellReuseIdentifier:cellID];
    
    //自动布局
    [tabV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        //与屏幕大小相同
        make.edges.mas_equalTo(self.view);
        
    }];
    
}

#pragma mark
#pragma mark - 设置tableView数据源方法
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 4;
}

//cell单元格
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
   
    //重用cell
    SettingTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    
    //cell赋值
    cell.textLabel.text = self.cellArr[indexPath.row];

    return cell;
    
}

#pragma mark
#pragma mark - 点击cell
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row == 3) {
        
        
        // 先把菊花移除掉
        [MBProgressHUD removeAllHudForWindow];
        
        [MBProgressHUD showSuccessMessage:@"注销成功"];
        
        // 写入文件
        NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
        
        [userDefaults setValue:@"" forKey:@"pwd"];
        
        [userDefaults synchronize];
        
        //刷新
        LeftViewController *leftVC = [LeftViewController new];
        
        self.sidePanelController.leftPanel = leftVC;
        
        //回到上一级
        [self.navigationController popViewControllerAnimated:YES];

    }
    
}

#pragma mark
#pragma mark - 内存警告
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
